home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PsL Monthly 1993 December
/
PSL Monthly Shareware CD-ROM (December 1993).iso
/
prgmming
/
dos
/
pascal
/
baseapp.exe
/
BAPP10.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1991-09-15
|
16KB
|
437 lines
PROGRAM BasicApp;
{(c) 1991 John C. Leon}
{Version 1.0 9/15/91}
{READ THESE COMMENTS BEFORE USING THIS CODE!}
{This base application was prepared for my personal use, as I do not wish
to recreate the wheel with each new TV application. Because I seem to
always want the same skeleton in my TV apps, this base set of code has become
very helpful!
Included in the base app is code for properly handling window numbers,
enabling a video mode toggle, providing tileable/cascadable windows,
testing for application-specific conditions before presenting the main
menu (and showing error message windows if there's a problem), and generating
a title screen on initialization.
All windows should be descendants of BWindow. Your descendants can
freely modify BWindow.Init and BWindow.Done. As long as they call
BWindow.Init and BWindow.Done, you can assure yourself that they will
be tilable/cascadable, and that window numbers will be properly handled.
The BaseApp.BaseWindow procedure opens an empty, generic window. This is
provided only so that you can see the use of the SetWinCount procedure, and
so that you can see properly working window numbers. To test it out, open
a few windows. Then close, say, window #2. Open a new window, and it will
use #2 (the first available window number). If only something as basic as
this was built into TV, eh?
A generic menubar and statusline are provided, including help contexts. This
will be extremely helpful for programmers struggling with how to implement
help contexts, if like me, you lost a lot of sleep getting it right the
first time!
The base app also includes code to put up a message box if the application
fails to initialize. That is, if you require certain conditions to be met
before your user can even start the app (data files must be present, etc)
you can initialize TV anyway and use a message box to state the cause of
failure. For this reason, the base application uses the TVision sample unit
MSGBOX (a VERY useful set of routines!). To illustrate how this works, THE
BASE APP REQUIRES THAT THE SOURCE CODE FILE (or any file named BASEAPP.PAS)
BE PRESENT IN THE CURRENT DIRECTORY.
If you find this code helpful, I'd appreciate a whopping $10. This'll buy
you copies of any future utilities, versions, etc, and the legal right to
use this software. This is SHAREWARE, folks, *NOT* freeware or public
domain. Act accordingly.
Constructive criticism and suggestions always welcome.
John C. Leon
3807 Wood Gardens Court
Kingwood, TX 77339
CIS 72426,2077
N.B. The ColBackground routines (the code to change background color) are
taken directly from Neil J. Rubenking's book, Turbo Pascal 6.0
Techniques and Utilities...a MUST for your collection).
Attention Btrieve programmers! My object-oriented unit for handling
standard Btrieve files is available currently as FREEWARE. Makes
TP6 Btrieve programming a snap! It is available on CIS in forum
BPROGA, library 1 (OOP). Just browse for file BTP*.ZIP
(* = version number).
}
USES
App, Dialogs, Objects, Menus, Views, Drivers, MsgBox;
CONST
cmSetVideoMode = 100;
cmBaseWindow = 110;
cmAbout = 120;
ErrorInitializing : integer = 0;
WinCount : integer = 0;
TYPE
BaseApp = object(TApplication)
constructor Init;
procedure InitMenuBar ; virtual;
procedure InitStatusLine; virtual;
procedure TitleScreen;
procedure TileAll;
procedure CascadeAll;
procedure SetVideoMode;
procedure BaseWindow;
procedure HandleEvent(var Event: TEvent); virtual;
destructor Done; virtual;
end;
PColBackground = ^ColBackground;
ColBackground = object(TBackground)
Color: Byte;
constructor Init(var Bounds: TRect; APat: Char;
AColor: Byte);
procedure Draw; virtual;
end;
PHelpStatusLine = ^THelpStatusLine;
THelpStatusLine = object(TStatusLine)
function Hint(AHelpCtx: Word): string; virtual;
end;
PWindow = ^BWindow;
BWindow = object(TWindow)
constructor Init(var Bounds: TRect; WinTitle: string;
WinNumber: integer);
destructor Done; virtual;
end;
VAR
BApp : BaseApp;
WinNumberCollection : PStringCollection; {initialized during BaseApp.Init}
WinNumberString : string;
RequiredFile : text; {NOT required for basic app, but is used as
an illustration of message box use if app's
required files/conditions are not met and
you DON'T want user to 'enter' application.}
constructor BaseApp.Init;
var
R : TRect;
Counter: integer;
Control: word;
begin
{Set up the collection of window numbers, sorted automatically from 1 to 9.}
WinNumberCollection := New(PStringCollection, Init(9,0));
for Counter := 1 to 9 do
begin
str(Counter,WinNumberString);
WinNumberCollection^.Insert(NewStr(WinNumberString));
end;
{NOTE: The variable 'ErrorInitializing' MUST be assigned before calling
TApplication.Init, as TApplication.Init will internally initialize the
menu and status line. The base application's overrides of InitMenuBar and
InitStatusLine depend on ErrorInitializing being assigned. This location
in the BaseApp.Init is where you'd put your various app initialization
tests. See the case statement below for actions to take on failure of
your initializations.}
assign(RequiredFile,'BaseApp.Pas');
{$I-} reset(RequiredFile); {$I+}
if ioresult <> 0 then
ErrorInitializing := 1;
{Call ancestor.}
TApplication.Init;
{Replace background with one of new color. Credit to Neil J. Rubenking's
book, Turbo Pascal 6.0 Techniques and Utilities for this code.}
Desktop^.Background^.GetExtent(R);
Desktop^.Delete(Desktop^.Background);
Dispose(Desktop^.Background, done);
Desktop^.Background := New(PColBackground, Init(R, #176, 9));
Desktop^.Insert(Desktop^.Background);
{No windows open at initialization, so disable the Tile and Cascade cmds
on menu.}
DisableCommands([cmTile, cmCascade]);
{Universally turn off the Video Mode option on menu if user screen can't
handle it.}
if HiResScreen = false then
DisableCommands([cmSetVideoMode]);
{Put up a generic title screen. Note what's done if there's an error
initializing your app. Expand this case statement as required to put
up different messages depending on which of you application's requirements
was not met.}
case ErrorInitializing of
0: TitleScreen;
1: Control := MessageBox(^C'Required file not found'^M^C'Cannot run Base App',
nil, mfError + mfOKButton);
end;
end;
destructor BaseApp.Done;
begin
TApplication.Done;
dispose(WinNumberCollection, Done); {Call this AFTER calling ancestor!}
end;
procedure SetWinCount;
function GetWinCount(WString: PString): boolean; far;
begin
GetWinCount := WString <> nil; {effectively sets position to first}
end; {*available* window number! }
var
Code : integer;
PWinNumber : pointer;
begin
if WinNumberCollection^.Count = 0 then {if #'s 1 thru 9 have been used}
WinCount := wnNoNumber
else
begin
PWinNumber := WinNumberCollection^.FirstThat(@GetWinCount);
WinNumberString := string(PWinNumber^);
val(WinNumberString, WinCount, Code);
WinNumberCollection^.Delete(PWinNumber);
disposestr(PWinNumber);
end;
end;
constructor ColBackground.Init(var Bounds: TRec